package cn.share.life.module.images.utils.flowFile;

import cn.hutool.poi.excel.ExcelUtil;
import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.io.File;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

@AllArgsConstructor
@Getter
public class NumberEnums {
//    // 电规规划号
//    ELECTRICITY_REGULATION_PLANNING("电规规划", "号"),
//    //发改能源号
//    DEVELOPMENT_REFORM_ENERGY("发改能源", "号"),
//    //国家电网基建号
//    STATE_GRID_INFRASTRUCTURE("国家电网基建", "号"),
//    //国家电网特号
//    STATE_GRID_SPECIAL("国家电网特", "号"),
//    //电规电网号
//    ELECTRICITY_REGULATION_GRID("电规电网", "号"),
//    //大地泰华基建字号
//    EARTH_TAIHUA_INFRASTRUCTURE("大地泰华基建字", "号"),
//    //国家电网设备号
//    STATE_GRID_EQUIPMENT("国家电网设备", "号"),
//    //中审亚太审字号
//    ASIA_PACIFIC_AUDIT("中审亚太审字", "号"),
//    //中汇会专号
//    CHINA_HUI_SPECIAL("中汇会专", "号"),
//    //国家电网财号
//    STATE_GRID_FINANCE("国家电网财", "号"),
//    //发改价格号
//    DEVELOPMENT_REFORM_PRICE("发改价格", "号"),
//    //发改价格规号
//    DEVELOPMENT_REFORM_PRICE_REGULATION("发改价格规", "号"),
//    //鲁中识信专审字号
//    LUZHONG_SHIXIN_SPECIAL_AUDIT("鲁中识信专审字", "号"),
//    //大地津泰专审字号
//    EARTH_JINTAI_SPECIAL_AUDIT("大地津泰专审字", "号"),
//    //电规智网号
//    ELECTRICITY_REGULATION_INTELLIGENT_GRID("电规智网", "号")
//    ;
//    private final String prefix;
//    private final String suffix;

    public static String getNumber(String str, List<String> numberRegexList) {
        if (!str.contains("号")) {
            return "";
        }
        // […]京会兴鉴字第……号
        if (str.contains("京会兴鉴字")) {
            String number2 = getNumber2(str, "\\[\\d{4}]京会兴鉴字.*?号");
            if (StringUtils.isBlank(number2)) {
                number2 = getNumber2(str, "〔\\d{4}〕京会兴鉴字.*?号");
            }
            return number2;
        }
        // […]京会兴核字第……号
        if (str.contains("京会兴核字")) {
            String number2 = getNumber2(str, "\\[\\d{4}]京会兴核字.*?号");
            if (StringUtils.isBlank(number2)) {
                number2 = getNumber2(str, "〔\\d{4}〕京会兴核字.*?号");
            }
            return number2;
        }

        for (String numberRegex : numberRegexList) {
            String[] split = numberRegex.split("……");
            if (str.contains(split[0])) {
                return getNumber(str, split[0], split[1]);
            }
        }
        return ""; // 或抛出异常
    }

    public static String getNumber2(String text, String prefix) {
        List<String> numberList = getNumber(text, prefix);
        System.out.println("getNumber0: " + numberList); // 输出：京会兴鉴字第111223(00)号
        if (numberList.isEmpty()) {
            return "";
        } else {
            return numberList.get(0);
        }
    }

    public static void main(String[] args) {
        String str = "7.[2019]京会兴鉴字第09000227号-国网新疆检修公司±800kV天山站阀冷系统逻辑优化及控制模块改造.pdf";
        String number2 = getNumber2(str, "\\[\\d{4}]京会兴鉴字.*?号");
        if (StringUtils.isBlank(number2)) {
            number2 = getNumber2(str, "〔\\d{4}〕京会兴鉴字.*?号");
        }
        System.out.println(number2);
    }

    public static String getNumber(String text, String prefix, String suffix) {
        String regex = prefix + "(.*?)" + suffix;
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(text);
        if (matcher.find()) {
            // 获取匹配的数字部分
            String day = matcher.group(1);
            // 构造结果字符串
            String result = prefix + day + suffix;
            System.out.println("getNumber1: " + result); // 输出：我们20号出差
            return result;
        }
        return "";
    }

    public static List<String> getNumber(String text, String regex) {
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(text);
        List<String> results = Lists.newArrayList();
        while (matcher.find()) {
            // 获取匹配的数字部分
            String result = matcher.group();
            System.out.println("getNumber2: " + result); // 输出：我们20号出差
            results.add(result);
        }
        return results;
    }
}
